package com.cyl.manager.pms.controller;

import com.cyl.manager.pms.domain.vo.ProductCategoryVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.sincere.common.annotation.Log;
import com.sincere.common.core.controller.BaseController;
import com.sincere.common.enums.BusinessType;
import com.cyl.manager.pms.service.ProductCategoryService;
import com.cyl.manager.pms.req.ProductCategoryReq;
import com.cyl.manager.pms.req.ProductCategoryQueryReq;
import com.cyl.manager.pms.resp.ProductCategoryResp;

import java.util.List;

/**
 * 商品分类Controller
 * 
 * @author zcc
 * @date 2022-11-28
 */
@Api("商品分类管理接口列表")
@RestController
@RequestMapping("/pms/productCategory")
@RequiredArgsConstructor
public class ProductCategoryController extends BaseController {

    private final ProductCategoryService productCategoryService ;

    @ApiOperation("查询商品分类列表")
    @PreAuthorize("@ss.hasPermi('pms:category:list')")
    @PostMapping("/list")
    public ResponseEntity<List<ProductCategoryVO>> list(@RequestBody ProductCategoryQueryReq query) {
        return ResponseEntity.ok(productCategoryService.queryProductCategory(query));
    }

    @ApiOperation("获取商品分类详细信息")
    @PreAuthorize("@ss.hasPermi('pms:category:query')")
    @GetMapping(value = "/{id}")
    public ResponseEntity<ProductCategoryResp> getInfo(@PathVariable("id") Long id) {
        return ResponseEntity.ok(productCategoryService.queryProductCategoryDetail(id));
    }

    @ApiOperation("新增商品分类")
    @PreAuthorize("@ss.hasPermi('pms:category:add')")
    @Log(title = "商品分类", businessType = BusinessType.INSERT)
    @PostMapping
    public ResponseEntity<Boolean> create(@RequestBody ProductCategoryReq req) {
        return ResponseEntity.ok(productCategoryService.create(req));
    }

    @ApiOperation("修改商品分类")
    @PreAuthorize("@ss.hasPermi('pms:category:edit')")
    @Log(title = "商品分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResponseEntity<Boolean> update(@RequestBody ProductCategoryReq req) {
        return ResponseEntity.ok(productCategoryService.update(req));
    }

    @ApiOperation("删除商品分类")
    @PreAuthorize("@ss.hasPermi('pms:category:remove')")
    @Log(title = "商品分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{id}")
    public ResponseEntity<Boolean> remove(@PathVariable Long id) {
        return ResponseEntity.ok(productCategoryService.deleteById(id));
    }
}
